package com.knowledge.graph.controller;

import com.knowledge.graph.model.vo.StatusCode;
import com.knowledge.graph.service.CourseService;
import com.knowledge.graph.model.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author jiwenlong
 * @version 1.0
 * @description: 处理有关课程的请求
 * @date 2023/11/8 18:30
 */
@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/course")
    public ResponseVO getCourse(@RequestParam("userID") Long userID) throws IOException {
        return courseService.getCourse(userID);
    }

    @GetMapping("/courseID")
    public ResponseVO getCourseByID(@RequestParam("courseID") Integer courseID) throws IOException {
        return courseService.getCourseByID(courseID);
    }

    @PostMapping("/course")
    public ResponseVO addCourse(@RequestParam("courseName") String courseName, @RequestParam("userID") Long userID,
                                @RequestParam("courseImage") MultipartFile courseImage, @RequestParam("courseDescription") String courseDescription) {
        return courseService.addCourse(courseName, courseImage, courseDescription, userID);
    }

    @PutMapping("/course")
    public ResponseVO updateCourse(@RequestParam("courseID") Integer courseID, @RequestParam("courseName") String courseName,
                                   @RequestParam("courseImage") MultipartFile courseImage, @RequestParam("courseDescription") String courseDescription) {
        return courseService.updateCourse(courseID, courseName, courseImage, courseDescription);
    }

    @DeleteMapping("/course")
    public ResponseVO deleteCourse(@RequestParam("courseID") Integer courseID) {
        return courseService.deleteCourse(courseID);
    }

    /**
     * @description: 生成课程邀请码
     * @param: 课程id
     * @return:
     * @author jiwenlong
     * @date: 2024/2/26 21:59
     */
    @PostMapping("/course/code")
    public ResponseVO putGradeOfInvitationCode(@RequestParam("courseId") Long courseId) {
        return courseService.postCourseOfInvitationCode(courseId);
    }

    @GetMapping("/student/courseList")
    public ResponseVO getCourseListByUser(@RequestParam("id") Long userId) throws IOException {
        if (userId == null) {
            return new ResponseVO(StatusCode.FAIL_SELECT.getCode(), StatusCode.FAIL_SELECT.getMessage());
        }
        return courseService.queryClassByUser(userId);
    }

}
